#coding = utf-8

import requests
from bs4 import BeautifulSoup

def weather_gat():
    header = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36',
        'Host': 'www.weather.com.cn',
        'Upgrade-Insecure-Requests': '1',
    }

    html = requests.get('http://www.weather.com.cn/textFC/gat.shtml',headers=header)

    content = html.content
    soup = BeautifulSoup(content,'lxml')
    conMidtab = soup.find('div',class_='conMidtab')
    tr_list = conMidtab.find_all('tr')[:11]
    imformation = [2,5,8,9,10]
    for i in range(5):
        j = imformation[i]
        if i < 3:
            td_list = tr_list[j].find_all('td')
            province = td_list[0].text.replace('\n', '')
            city = td_list[1].text.replace('\n', '')
            max = td_list[4].text.replace('\n', '')
            min = td_list[7].text.replace('\n', '')
            print('%s|%s|%s'%(province+city,max,min))
        else:
            td_list = tr_list[j].find_all('td')
            city = td_list[0].text.replace('\n', '')
            max = td_list[3].text.replace('\n', '')
            min = td_list[6].text.replace('\n', '')
            print('%s|%s|%s'%(province+city,max,min))
weather_gat()